home *** CD-ROM | disk | FTP | other *** search
- //========================================================================================
- //
- // File: EditCmds.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef EDITCMDS_H
- #include "EditCmds.h"
- #endif
-
- #ifndef CONTAINERSEL_H
- #include "ContainerSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef CONTAINERPART_H
- #include "ContainerPart.h"
- #endif
-
- #ifndef CONTAINERFRM_H
- #include "ContainerFrm.h"
- #endif
-
- #ifndef CONTAINERLINK_H
- #include "ContainerLink.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment containercommand
- #endif
-
- //========================================================================================
- // CContainerEditCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand constructor
- //----------------------------------------------------------------------------------------
-
- CContainerEditCommand::CContainerEditCommand (Environment *ev,
- ODCommandID commandID,
- CContainerPart* part,
- CContainerFrame* frame,
- CContainerSelection* selection,
- FW_Boolean canUndo) :
- FW_CEditCommand(ev, commandID, frame, canUndo),
- fContainerPart(part),
- fContainerSelection(selection),
- fShapeCollection(NULL),
- fSavedLink(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand destructor
- //----------------------------------------------------------------------------------------
-
- CContainerEditCommand::~CContainerEditCommand()
- {
- if (fShapeCollection)
- delete fShapeCollection;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::DoPaste
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::DoPaste(Environment *ev) // Override
- {
- fContainerSelection->AdjustSelectionAfterPaste(ev, fFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::DoPasteAs
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::DoPasteAs(Environment *ev) // Override
- {
- // Select the newly-subscribed shapes
- fSavedLink = GetContainerLinkManager(ev)->GetLatestSubscriber(ev);
- fSavedLink->SelectShapes(ev);
-
- // Offset the selection, saving the offset for later updates
- FW_CPoint offset = fContainerSelection->AdjustSelectionAfterPaste(ev, fFrame);
-
- // Save information about newly-created link
- fSavedLink->SetUpdateOffset(ev, offset);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::CommitUndone
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::CommitUndone(Environment* ev) // Override
- {
- if (fCommandID == kODCommandPasteAs)
- GetContainerLinkManager(ev)->CommitUndone(ev, fSavedLink);
- else
- FW_CEditCommand::CommitUndone(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::SaveUndoState(Environment *ev) // Override
- {
- if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
- {
- this->SaveShapeSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::SaveRedoState(Environment *ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- {
- this->SaveShapeSelection(ev);
- }
- else if (fCommandID == kODCommandPasteAs)
- {
- // Newly-created link has already been saved in DoPasteAs
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::FreeUndoState(Environment* ev) // Override
- {
- if (fCommandID == kODCommandCut || fCommandID == kODCommandClear)
- this->DeleteSavedShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::FreeRedoState(Environment* ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- this->DeleteSavedShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::UndoIt(Environment *ev) // Override
- {
- FW_CEditCommand::UndoIt(ev); // call inherited
-
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestoreShapeSelection(ev);
- break;
-
- case kODCommandPaste:
- this->RemoveShapeSelection(ev);
- break;
-
- case kODCommandPasteAs:
- GetContainerLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::RedoIt(Environment *ev) // Override
- {
- FW_CEditCommand::RedoIt(ev); // call inherited
-
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemoveShapeSelection(ev);
- break;
-
- case kODCommandPaste:
- this->RestoreShapeSelection(ev);
- break;
-
- case kODCommandPasteAs:
- GetContainerLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::RemoveShapeSelection
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::RemoveShapeSelection(Environment *ev)
- {
- // First, empty the selection
- fContainerSelection->CloseSelection(ev);
-
- // Select the saved shapes
- this->SelectSavedShapes(ev);
-
- // Clear the selected shapes
- fContainerSelection->ClearSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::RestoreShapeSelection
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::RestoreShapeSelection(Environment *ev)
- {
- // First, empty the selection
- fContainerSelection->CloseSelection(ev);
-
- // Add the saved shapes back into the part
- FW_COrderedCollectionIterator ite(fShapeCollection);
- for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->RestoreShape(ev, fContainerPart);
- }
-
- // Add the saved shapes to the selection
- this->SelectSavedShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::SaveShapeSelection
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::SaveShapeSelection(Environment *ev)
- {
- // Save references to selected shapes
- fShapeCollection = new FW_CPrivOrderedCollection;
-
- // Copy shape pointers from fContainerSelection
- FW_COrderedCollectionIterator ite(fContainerSelection->GetSelectionCollection());
- for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- fShapeCollection->AddLast(shape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::SelectSavedShapes
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::SelectSavedShapes(Environment *ev)
- {
- // Add the shapes in fShapeCollection to fContainerSelection
- FW_COrderedCollectionIterator ite(fShapeCollection);
- for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- fContainerSelection->AddToSelection(ev, shape, FALSE);
- fContainerSelection->RecontainerShape(ev, shape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::DeleteSavedShapes
- //----------------------------------------------------------------------------------------
- void CContainerEditCommand::DeleteSavedShapes(Environment *ev)
- {
- CBaseShape* shape;
-
- // before deleting the shape check if they are not promised
- FW_COrderedCollectionIterator ite(fShapeCollection);
- for (shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- shape->CheckPromise(ev, fContainerPart);
- }
-
- // ----- Delete all the shapes -----
- while ((shape = (CBaseShape*)fShapeCollection->First()) != NULL)
- {
- fShapeCollection->Remove(shape);
- delete shape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerEditCommand::GetContainerLinkManager
- //----------------------------------------------------------------------------------------
- CContainerLinkManager* CContainerEditCommand::GetContainerLinkManager(Environment* ev) const
- {
- return (CContainerLinkManager*) fPart->GetLinkManager(ev);
- }
-